package com.example.demo.lc.dp;

/**
* @author wzh
* @date 2021/7/22 8:33 下午
* @Description   dp
 * https://leetcode-cn.com/problems/coin-change/
*/
public class LeetCode322 {
    public static void main(String[] args) {
        //int[] coins = {1, 2, 5};
        //int amount = 11;
        //int[] coins = {2};
        //int amount = 3;
        int[] coins = {1};
        int amount = 0;
        System.out.println(coinChange(coins,amount));
    }

    public static int coinChange(int[] coins, int amount) {
        if(coins.length == 0){
            return -1;
        }
        int[] dp = new int[amount+1];
        dp[0] = 0;
        for (int i = 1; i <= amount; i++) {
            int min = Integer.MAX_VALUE;
            for (int j = 0; j < coins.length; j++) {
                if(i-coins[j] >= 0 && dp[i-coins[j]] < min){
                    min = dp[i-coins[j]]+1;
                }
            }
            dp[i] = min;
        }
        return dp[amount] != Integer.MAX_VALUE?dp[amount]:-1;
    }

}
